package Tests;

import Common.TestBase;
import Pages.LandingPage;
import Pages.MenuPages;

import org.openqa.selenium.By;
import org.testng.annotations.*;
import java.lang.reflect.Method;

import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertEquals;

/**
 * Navigation menu test. Could be failed if you try to move mouse.
 */
public class NavigationMenuTest extends TestBase{

    protected static MenuPages menu = new MenuPages();
    protected static LandingPage landing = new LandingPage();
    @BeforeMethod (groups = {"done","nonstable"})
    public void beforeMethod(final Method method) {
        hb.openBaseUrl();}

    //Main menu test
    @Test (groups = { "done" })
    public void menuTest() {
        for (int i=0; i<=7; i++) {
            hb.click(By.xpath(menu.Menu(i)));
            assertTrue(hb.isElementsLocated(By.xpath("//*[contains(text(),'" + menu.menuPage(i) + "')]")));
        }
    }

    //technologies sub menu test
    @Test (groups = { "done" })
    public void technologiesTest(){
        for (int i=0; i<=21; i++) {
            hb.moveTheMouse(hb.findElement(By.xpath(landing.technologies())));
            hb.isElementPresent(By.xpath("//*[@href='" + menu.technologiesMenu(i) + "']"));
            hb.click(By.xpath("//*[@href='" + menu.technologiesMenu(i) + "']"));
            assertTrue(hb.isElementsLocated(By.xpath("//*[contains(text(),'" + menu.technologiesPage(i) + "')]")));
        }
    }

    //news sub menu test
    @Test (groups = { "done" })
    public void newsTest(){
        for (int i=0; i<=3; i++) {
            hb.moveTheMouse(hb.findElement(By.xpath(landing.news())));
            hb.isElementPresent(By.xpath("//*[@href='" + menu.newsMenu(1) + "']"));
            hb.click(By.xpath("//*[@href='" + menu.newsMenu(i) + "']"));
            assertTrue(hb.isElementsLocated(By.xpath("//*[contains(text(),'" + menu.newsPage(i) + "')]")));
        }
    }

    //markets sub menu test
    @Test (groups = { "done" })
    public void marketsTest(){
        for (int i=0; i<=6; i++) {
            hb.moveTheMouse(hb.findElement(By.xpath(landing.markets())));
            hb.isElementPresent(By.xpath("//*[@href='" + menu.marketsMenu(1) + "']"));
            hb.click(By.xpath("//*[@href='" + menu.marketsMenu(i) + "']"));
            assertTrue(hb.isElementsLocated(By.xpath("//*[contains(text(),'" + menu.marketsPage(i) + "')]")));
        }
    }

    //community sub menu test
    @Test (groups = { "done" })
    public void communityTest(){
        for (int i=0; i<=1; i++) {
            hb.moveTheMouse(hb.findElement(By.xpath(landing.community())));
            hb.isElementPresent(By.xpath("//*[@href='" + menu.communityMenu(1) + "']"));
            hb.click(By.xpath("//*[@href='" + menu.communityMenu(i) + "']"));
            assertTrue(hb.isElementsLocated(By.xpath("//*[contains(text(),'" + menu.communityPage(i) + "')]")));
        }
    }

    //paginator test
    @Test (groups = { "done" })
    public void paginatorNextPage(){
        application.goToTechnologiesPage();
        application.nextPage();
        assertTrue(hb.isElementsLocated(By.xpath(landing.activePage())));
    }
}
